﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace PostSharp4ViewState.Tests
{
   public class TestWithoutOverrides : BaseControl
   {
      [Persist(Mode = PersistMode.ViewState)]
      public string StringValue;

      [Persist(Mode = PersistMode.ViewState)]
      public int IntValue;

      [Persist(Mode = PersistMode.ControlState)]
      public string StringCSValue;

      [Persist(Mode = PersistMode.ControlState)]
      public int IntCSValue;
   }
   [TestClass]
   public class TestWithoutOverridesTest
   {

      [TestMethod]
      public void GeneratedLoadControlStateWorks()
      {
         TestWithoutOverrides o = new TestWithoutOverrides();
         o.DoLoadControlState(new object[] { null, new object[] {4, "value" }});
         Assert.AreEqual("value", o.StringCSValue);
         Assert.AreEqual(4, o.IntCSValue);
      }
      [TestMethod]
      public void GeneratedSaveControlStateWorks()
      {
         TestWithoutOverrides o = new TestWithoutOverrides();
         o.IntCSValue = 4;
         o.StringCSValue = "value";
         object[] state = (object[])o.DoSaveControlState();
         Assert.IsNull(state[0]);
         Assert.IsInstanceOfType(state[1], typeof(object[]));
         state = (object[])state[1];
         Assert.AreEqual(state[0], 4);
         Assert.AreEqual(state[1], "value");
      }

      [TestMethod]
      public void GeneratedLoadViewStateWorks()
      {
         TestWithoutOverrides o = new TestWithoutOverrides();
         o.DoLoadViewState(new object[] { null, new object[] {4, "value"} });
         Assert.AreEqual("value", o.StringValue);
         Assert.AreEqual(4, o.IntValue);
      }
      [TestMethod]
      public void GeneratedSaveViewStateWorks()
      {
         TestWithoutOverrides o = new TestWithoutOverrides();
         o.IntValue = 4;
         o.StringValue = "value";
         object[] state = (object[])o.DoSaveViewState();
         Assert.IsNull(state[0]);
         Assert.IsInstanceOfType(state[1], typeof(object[]));
         state = (object[])state[1];
         Assert.AreEqual(state[0], 4);
         Assert.AreEqual(state[1], "value");
      }
   }
}
